package com.tomtop.core.utils;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;

import com.tomtop.core.Context;
import com.tomtop.core.model.SysUser;
import com.tomtop.core.service.IsAppService;
import com.tomtop.core.service.LoginService;

public class ContextUtils {
	static LoginService loginService;
	static IsAppService isAppService;
	
	@Autowired(required=false) void set(LoginService loginService,IsAppService isAppService) {
		ContextUtils.loginService = loginService;
		ContextUtils.isAppService = isAppService;
	}
	
	public static Optional<SysUser> initLoginInfo(){
		Optional<SysUser> user;
		if(loginService!=null)
			 user=Optional.of(loginService.findLoginUser());
		else
			 user=SysUser.now();
		Context.setUser(user);
		return user;
	}

	public static boolean isApp() {
		if(isAppService==null)
			return false;
		Boolean isapp=isAppService.isApp();
		if(isapp==null)
			return false;
		return true;
	}
}
